﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using pay.Entity;
using pay.BLL;
using System.Collections;
using System.Text;

public partial class test_PayHander : System.Web.UI.Page
{
    int productid = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (string.IsNullOrEmpty(Request["productid"]))
            {
                Response.Write("<script>alert('不存在此产品编号，请重新选择！'); this.history.back(-1);</script>");
                return;
            }
            
            //if (string.IsNullOrEmpty(Request["count"]))
            //{
            //    //Response.Write("<script>alert('产品数量不能为空！'); this.history.back(-1);</script>");
            //    //return;
                

            //}
            productid = Convert.ToInt32(Request["productid"]);
            switch(productid)
            {
                case 1:
                    productid =54; //（益盟超盘手专业版12个月版1元版）
                    break;
                case 2:
                    productid = 55; //(99元版)
                    break;
                case 3:
                    productid = 56;//(199元版)
                    break;
                case 4:
                    productid = 57;//(299元版)
                    break;
                case 5:
                    productid = 58;//(399元版)
                    break;
                default:
                    break;
            }
            if (string.IsNullOrEmpty(Request["uname"]))
            {
                Response.Write("<script>alert('用户姓名不能为空!'); this.history.back(-1);</script>");
                return;
            }
            if (string.IsNullOrEmpty(Request["tel"]))
            {
                Response.Write("<script>alert('联系电话不能为空！!'); this.history.back(-1);</script>");
                return;

            }
            var t = Request["sourceType"];
            if (string.IsNullOrEmpty(Request["sourceType"]))
            {
                sourceType =1;
            }
            else
            {
               sourceType =int.Parse(Request["sourceType"]);
            }
           
            Buy_Product();
        }
    }

  
    public void Buy_Product()
    {
        List<ShopCard> lst = null;
        ShopCard sc = null;
       
        uname = Request["uname"].ToString();
        tel = Request["tel"].ToString();
     
        if (Session["EmoneyShopCard"] == null)
        {
            try
            {
                lst = new List<ShopCard>();
                sc = new ShopCard();
                //sc.Count = Convert.ToInt32(Request["count"]);
                sc.Count = 1;
               // sc.ProductId = Convert.ToInt32(Request["productid"]);
                sc.ProductId = productid;
                lst.Add(sc);
                Session["EmoneyShopCard"] = lst;
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('" + ex.Message + "'); this.history.back(-1);</script>");
            }

        }

        else
        {


            lst = (List<ShopCard>)Session["EmoneyShopCard"];
            bool flag = true;

            for (int i = 0; i < lst.Count; i++)
            {
                sc = lst[i];
                if (Convert.ToInt32(Request["productid"]) == sc.ProductId)
                {
                    //sc.Count = Convert.ToInt32(Request["count"]);//数量
                    sc.Count = 1;
                    flag = false;
                }
            }
            if (flag)
            {
                sc = new ShopCard();
                //sc.Count = Convert.ToInt32(Request["count"]);
                sc.Count = 1;
                //sc.ProductId = Convert.ToInt32(Request["productid"]);
                sc.ProductId = productid;
                lst.Add(sc);
            }
            Session["EmoneyShopCard"] = lst;

        }
    }

    public string uname 
    {
        get;
        set;
    }
    public string tel
    {
        get;
        set;
    }
    public int sourceType
    {
        get;
        set;
    } //来源

}